home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 002 / emacssrc.arc / ESTRUCT.H < prev    next >
C/C++ Source or Header  |  1987-02-16  |  19KB  |  483 lines

  1. /*    ESTRUCT:    Structure and preprocesser defined for
  2.             MicroEMACS 3.8
  3.  
  4.             written by Dave G. Conroy
  5.             modified by Steve Wilhite, George Jones
  6.             greatly modified by Daniel Lawrence
  7. */
  8.  
  9. #ifdef    LATTICE
  10. #undef    LATTICE        /* don't use their definitions...use ours    */
  11. #endif
  12. #ifdef    MSDOS
  13. #undef    MSDOS
  14. #endif
  15. #ifdef    CPM
  16. #undef    CPM
  17. #endif
  18. #ifdef    AMIGA
  19. #undef    AMIGA
  20. #endif
  21.  
  22. /*    Version definition            */
  23.  
  24. #define    VERSION    "3.8f"
  25.  
  26. /*    Machine/OS definitions            */
  27.  
  28. #define AMIGA   0                       /* AmigaDOS            */
  29. #define ST520   0                       /* ST520, TOS                   */
  30. #define MSDOS   1                       /* MS-DOS                       */
  31. #define V7      0                       /* V7 UN*X or Coherent or BSD4.2*/
  32. #define    BSD    0            /* UNIX BSD 4.2    and ULTRIX    */
  33. #define    USG    0            /* UNIX system V        */
  34. #define VMS     0                       /* VAX/VMS                      */
  35. #define CPM     0                       /* CP/M-86                      */
  36. #define    FINDER    0            /* Macintosh OS            */
  37.  
  38. /*    Compiler definitions            */
  39. #define MWC86   0    /* marc williams compiler */
  40. #define    LATTICE    1    /* Lattice 2.14 thruough 3.0 compilers */
  41. #define    AZTEC    0    /* Aztec C 3.20e */
  42. #define    MSC    0    /* MicroSoft C compile version 3 */
  43.  
  44. /*    Profiling options    */
  45. #define    APROF    0    /* turn Aztec C profiling on? */
  46. #define    NBUCK    100    /* number of buckets to profile */
  47. #define    RAMSIZE    0    /* dynamic RAM memory usage tracking */
  48. #define    RAMSHOW    0    /* auto dynamic RAM reporting */
  49.  
  50. /*   Special keyboard definitions            */
  51.  
  52. #define WANGPC    0        /* WangPC - mostly escape sequences     */
  53.  
  54. /*    Terminal Output definitions        */
  55.  
  56. #define ANSI    0            /* ansi escape sequences    */
  57. #define    HP150    1            /* HP150 screen driver        */
  58. #define    HP110    0            /* HP110 screen driver        */
  59. #define    VMSVT    0            /* various VMS terminal entries    */
  60. #define VT52    0                       /* VT52 terminal (Zenith).      */
  61. #define VT100   0                       /* Handle VT100 style keypad.   */
  62. #define LK201   0                       /* Handle LK201 style keypad.   */
  63. #define RAINBOW 0                       /* Use Rainbow fast video.      */
  64. #define TERMCAP 0                       /* Use TERMCAP                  */
  65. #define    IBMPC    0            /* IBM-PC CGA/MONO driver    */
  66. #define    EGA    0            /* EGA IBM-PC specific driver    */
  67. #define    DG10    0            /* Data General system/10    */
  68. #define    TIPC    0            /* TI Profesional PC driver    */
  69. #define    MAC    0            /* Macintosh            */
  70. #define    ATARI    0            /* Atari 520/1040ST screen    */
  71.  
  72. /*    Configuration options    */
  73.  
  74. #define CVMVAS  1    /* arguments to page forward/back in pages    */
  75. #define    NFWORD    1    /* forward word jumps to beginning of word    */
  76. #define    CLRMSG    0    /* space clears the message line with no insert    */
  77. #define    ACMODE    1    /* auto CMODE on .C and .H files        */
  78. #define    CFENCE    1    /* fench matching in CMODE            */
  79. #define    TYPEAH    1    /* type ahead causes update to be skipped    */
  80. #define DEBUGM    1    /* Global SPELL mode triggers macro debugging    */
  81. #define    VISMAC    0    /* update display during keyboard macros    */
  82. #define    CTRLZ    0    /* add a ^Z at end of files under MSDOS only    */
  83.  
  84. #define    REVSTA    1    /* Status line appears in reverse video        */
  85. #define    COLOR    0    /* color commands and windows            */
  86.  
  87. #define    FILOCK    0    /* file locking under unix BSD 4.2        */
  88. #define    ISRCH    1    /* Incremental searches like ITS EMACS        */
  89. #define    WORDPRO    1    /* Advanced word processing features        */
  90. #define    FLABEL    1    /* function key label code            */
  91. #define    APROP    1    /* Add code for Apropos command            */
  92. #define    CRYPT    1    /* file encryption enabled?            */
  93. #define MAGIC    1    /* include regular expression matching?        */
  94.  
  95. #define ASCII    1    /* always using ASCII char sequences for now    */
  96. #define EBCDIC    0    /* later IBM mainfraim versions will use EBCDIC    */
  97.  
  98. /*    System dependant library redefinitions, structures and includes    */
  99.  
  100. #if    AZTEC
  101. #undef    fputc
  102. #undef    fgetc
  103. #define    fputc    aputc
  104. #define    fgetc    agetc
  105. #define    int86    sysint
  106. #define    intdos(a, b)    sysint(33, a, b)
  107. #define    inp    inportb
  108. #define    outp    outportw
  109.  
  110. struct XREG {
  111.     int ax,bx,cx,dx,si,di;
  112. };
  113.  
  114. struct HREG {
  115.     char al,ah,bl,bh,cl,ch,dl,dh;
  116. };
  117.  
  118. union REGS {
  119.     struct XREG x;
  120.     struct HREG h;
  121. };
  122. #endif
  123.  
  124. #if    MSDOS & MWC86
  125. #include    <dos.h>
  126. #define    int86(a, b, c)    intcall(b, c, a)
  127. #define    inp    in
  128.  
  129. struct XREG {
  130.     int ax,bx,cx,dx,si,di,ds,es,flags;
  131. };
  132.  
  133. struct HREG {
  134.     char al,ah,bl,bh,cl,ch,dl,dh;
  135.     int ds,es,flags;
  136. };
  137.  
  138. union REGS {
  139.     struct XREG x;
  140.     struct HREG h;
  141. };
  142. #endif
  143.  
  144. #if    MSDOS & MSC
  145. #include    <dos.h>
  146. #define    movmem(a, b, c)        memcpy(b, a, c)
  147. #endif
  148.  
  149. #if    MSDOS & LATTICE
  150. #undef    CPM
  151. #undef    LATTICE
  152. #include    <dos.h>
  153. #undef    CPM
  154. #endif
  155.  
  156. #if    VMS
  157. #define    unlink(a)    delete(a)
  158. #endif
  159.  
  160. /*    define memory mapped flag    */
  161.  
  162. #define    MEMMAP    0
  163.  
  164. #if    IBMPC
  165. #undef    MEMMAP
  166. #define    MEMMAP    1
  167. #endif
  168.  
  169. #if    IBMMONO
  170. #undef    MEMMAP
  171. #define    MEMMAP    1
  172. #endif
  173.  
  174. #if    EGA
  175. #undef    MEMMAP
  176. #define    MEMMAP    1
  177. #endif
  178.  
  179. /*    internal constants    */
  180.  
  181. #define    NBINDS    256            /* max # of bound keys        */
  182. #define NFILEN  80                      /* # of bytes, file name        */
  183. #define NBUFN   16                      /* # of bytes, buffer name      */
  184. #define NLINE   256                     /* # of bytes, line             */
  185. #define    NSTRING    128            /* # of bytes, string buffers    */
  186. #define NKBDM   256                     /* # of strokes, keyboard macro */
  187. #define NPAT    128                     /* # of bytes, pattern          */
  188. #define HUGE    1000                    /* Huge number                  */
  189. #define    NLOCKS    100            /* max # of file locks active    */
  190. #define    NCOLORS    8            /* number of supported colors    */
  191. #define    KBLOCK    250            /* sizeof kill buffer chunks    */
  192. #define    NBLOCK    16            /* line block chunk size    */
  193. #define    NVSIZE    10            /* max #chars in a var name    */
  194.  
  195. #if    0
  196. #define AGRAVE  0x60                    /* M- prefix,   Grave (LK201)   */
  197. #define METACH  0x1B                    /* M- prefix,   Control-[, ESC  */
  198. #define CTMECH  0x1C                    /* C-M- prefix, Control-\       */
  199. #define EXITCH  0x1D                    /* Exit level,  Control-]       */
  200. #define CTRLCH  0x1E                    /* C- prefix,   Control-^       */
  201. #define HELPCH  0x1F                    /* Help key,    Control-_       */
  202. #endif
  203.  
  204. #define CTRL    0x0100                  /* Control flag, or'ed in       */
  205. #define META    0x0200                  /* Meta flag, or'ed in          */
  206. #define CTLX    0x0400                  /* ^X flag, or'ed in            */
  207. #define    SPEC    0x0800            /* special key (function keys)    */
  208.  
  209. #define FALSE   0                       /* False, no, bad, etc.         */
  210. #define TRUE    1                       /* True, yes, good, etc.        */
  211. #define ABORT   2                       /* Death, ^G, abort, etc.       */
  212. #define    FAILED    3            /* not-quite fatal false return    */
  213. #define    RET    4            /* a return from buffer        */
  214. #define    GOLINE    5            /* exit flagging a GOTO        */
  215.  
  216. #define    STOP    0            /* keyboard macro not in use    */
  217. #define    PLAY    1            /*          playing    */
  218. #define    RECORD    2            /*          recording    */
  219.  
  220. #define    FORWARD    0            /* forward direction        */
  221. #define REVERSE    1            /* backwards direction        */
  222.  
  223. #define FIOSUC  0                       /* File I/O, success.           */
  224. #define FIOFNF  1                       /* File I/O, file not found.    */
  225. #define FIOEOF  2                       /* File I/O, end of file.       */
  226. #define FIOERR  3                       /* File I/O, error.             */
  227. #define    FIOLNG    4            /* line longer than allowed len    */
  228. #define    FIOFUN    5            /* File I/O, eod of file/bad line*/
  229.  
  230. #define CFCPCN  0x0001                  /* Last command was C-P, C-N    */
  231. #define CFKILL  0x0002                  /* Last command was a kill      */
  232.  
  233. #define    BELL    0x07            /* a bell character        */
  234. #define    TAB    0x09            /* a tab character        */
  235.  
  236. #if    V7 | USG | BSD
  237. #define    PATHCHR    ':'
  238. #else
  239. #define    PATHCHR    ';'
  240. #endif
  241.  
  242. #define    INTWIDTH    sizeof(int)/3 + 2
  243.  
  244. /*    Macro argument token types                    */
  245.  
  246. #define    TKNUL    0            /* end-of-string        */
  247. #define    TKARG    1            /* interactive argument        */
  248. #define    TKBUF    2            /* buffer argument        */
  249. #define    TKVAR    3            /* user variables        */
  250. #define    TKENV    4            /* environment variables    */
  251. #define    TKFUN    5            /* function....            */
  252. #define    TKDIR    6            /* directive            */
  253. #define    TKLBL    7            /* line label            */
  254. #define    TKLIT    8            /* numeric literal        */
  255. #define    TKSTR    9            /* quoted string literal    */
  256. #define    TKCMD    10            /* command name            */
  257.  
  258. /*    Internal defined functions                    */
  259.  
  260. /* DIFCASE represents the integer difference between upper
  261.    and lower case letters.  It is an xor-able value, which is
  262.    fortunate, since the relative positions of upper to lower
  263.    case letters is the opposite of ascii in ebcdic.
  264. */
  265.  
  266. #ifdef    islower
  267. #undef    islower
  268. #endif
  269.  
  270. #if    ASCII
  271.  
  272. #define    DIFCASE        0x20
  273. #define isletter(c)    (('a' <= c && 'z' >= c) || ('A' <= c && 'Z' >= c))
  274. #define islower(c)    (('a' <= c && 'z' >= c))
  275. #endif
  276.  
  277. #if    EBCDIC
  278.  
  279. #define    DIFCASE        0x40
  280. #define isletter(c)    (('a' <= c && 'i' >= c) || ('j' <= c && 'r' >= c) || ('s' <= c && 'z' >= c) || ('A' <= c && 'I' >= c) || ('J' <= c && 'R' >= c) || ('S' <= c && 'Z' >= c))
  281. #define islower(c)    (('a' <= c && 'i' >= c) || ('j' <= c && 'r' >= c) || ('s' <= c && 'z' >= c))
  282. #endif
  283.  
  284. /*    Dynamic RAM tracking and reporting redefinitions    */
  285.  
  286. #if    RAMSIZE
  287. #define    malloc    allocate
  288. #define    free    release
  289. #endif
  290.  
  291. /*
  292.  * There is a window structure allocated for every active display window. The
  293.  * windows are kept in a big list, in top to bottom screen order, with the
  294.  * listhead at "wheadp". Each window contains its own values of dot and mark.
  295.  * The flag field contains some bits that are set by commands to guide
  296.  * redisplay; although this is a bit of a compromise in terms of decoupling,
  297.  * the full blown redisplay is just too expensive to run for every input
  298.  * character.
  299.  */
  300. typedef struct  WINDOW {
  301.         struct  WINDOW *w_wndp;         /* Next window                  */
  302.         struct  BUFFER *w_bufp;         /* Buffer displayed in window   */
  303.         struct  LINE *w_linep;          /* Top line in the window       */
  304.         struct  LINE *w_dotp;           /* Line containing "."          */
  305.         short   w_doto;                 /* Byte offset for "."          */
  306.         struct  LINE *w_markp;          /* Line containing "mark"       */
  307.         short   w_marko;                /* Byte offset for "mark"       */
  308.         char    w_toprow;               /* Origin 0 top row of window   */
  309.         char    w_ntrows;               /* # of rows of text in window  */
  310.         char    w_force;                /* If NZ, forcing row.          */
  311.         char    w_flag;                 /* Flags.                       */
  312. #if    COLOR
  313.     char    w_fcolor;        /* current forground color    */
  314.     char    w_bcolor;        /* current background color    */
  315. #endif
  316. }       WINDOW;
  317.  
  318. #define WFFORCE 0x01                    /* Window needs forced reframe  */
  319. #define WFMOVE  0x02                    /* Movement from line to line   */
  320. #define WFEDIT  0x04                    /* Editing within a line        */
  321. #define WFHARD  0x08                    /* Better to a full display     */
  322. #define WFMODE  0x10                    /* Update mode line.            */
  323. #define    WFCOLR    0x20            /* Needs a color change        */
  324.  
  325. /*
  326.  * Text is kept in buffers. A buffer header, described below, exists for every
  327.  * buffer in the system. The buffers are kept in a big list, so that commands
  328.  * that search for a buffer by name can find the buffer header. There is a
  329.  * safe store for the dot and mark in the header, but this is only valid if
  330.  * the buffer is not being displayed (that is, if "b_nwnd" is 0). The text for
  331.  * the buffer is kept in a circularly linked list of lines, with a pointer to
  332.  * the header line in "b_linep".
  333.  *     Buffers may be "Inactive" which means the files accosiated with them
  334.  * have not been read in yet. These get read in at "use buffer" time.
  335.  */
  336. typedef struct  BUFFER {
  337.         struct  BUFFER *b_bufp;         /* Link to next BUFFER          */
  338.         struct  LINE *b_dotp;           /* Link to "." LINE structure   */
  339.         short   b_doto;                 /* Offset of "." in above LINE  */
  340.         struct  LINE *b_markp;          /* The same as the above two,   */
  341.         short   b_marko;                /* but for the "mark"           */
  342.         struct  LINE *b_linep;          /* Link to the header LINE      */
  343.     char    b_active;        /* window activated flag    */
  344.         char    b_nwnd;                 /* Count of windows on buffer   */
  345.         char    b_flag;                 /* Flags                        */
  346.     char    b_mode;            /* editor mode of this buffer    */
  347.         char    b_fname[NFILEN];        /* File name                    */
  348.         char    b_bname[NBUFN];         /* Buffer name                  */
  349. #if    CRYPT
  350.     char    b_key[NPAT];        /* current encrypted key    */
  351. #endif
  352. }       BUFFER;
  353.  
  354. #define BFINVS  0x01                    /* Internal invisable buffer    */
  355. #define BFCHG   0x02                    /* Changed since last write     */
  356.  
  357. /*    mode flags    */
  358. #define    NUMMODES    8        /* # of defined modes        */
  359.  
  360. #define    MDWRAP    0x0001            /* word wrap            */
  361. #define    MDCMOD    0x0002            /* C indentation and fence match*/
  362. #define    MDSPELL    0x0004            /* spell error parcing        */
  363. #define    MDEXACT    0x0008            /* Exact matching for searches    */
  364. #define    MDVIEW    0x0010            /* read-only buffer        */
  365. #define MDOVER    0x0020            /* overwrite mode        */
  366. #define MDMAGIC    0x0040            /* regular expresions in search */
  367. #define    MDCRYPT    0x0080            /* encrytion mode active    */
  368.  
  369. /*
  370.  * The starting position of a region, and the size of the region in
  371.  * characters, is kept in a region structure.  Used by the region commands.
  372.  */
  373. typedef struct  {
  374.         struct  LINE *r_linep;          /* Origin LINE address.         */
  375.         short   r_offset;               /* Origin LINE offset.          */
  376.         long    r_size;                 /* Length in characters.        */
  377. }       REGION;
  378.  
  379. /*
  380.  * All text is kept in circularly linked lists of "LINE" structures. These
  381.  * begin at the header line (which is the blank line beyond the end of the
  382.  * buffer). This line is pointed to by the "BUFFER". Each line contains a the
  383.  * number of bytes in the line (the "used" size), the size of the text array,
  384.  * and the text. The end of line is not stored as a byte; it's implied. Future
  385.  * additions will include update hints, and a list of marks into the line.
  386.  */
  387. typedef struct  LINE {
  388.         struct  LINE *l_fp;             /* Link to the next line        */
  389.         struct  LINE *l_bp;             /* Link to the previous line    */
  390.         short   l_size;                 /* Allocated size               */
  391.         short   l_used;                 /* Used size                    */
  392.         char    l_text[1];              /* A bunch of characters.       */
  393. }       LINE;
  394.  
  395. #define lforw(lp)       ((lp)->l_fp)
  396. #define lback(lp)       ((lp)->l_bp)
  397. #define lgetc(lp, n)    ((lp)->l_text[(n)]&0xFF)
  398. #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
  399. #define llength(lp)     ((lp)->l_used)
  400.  
  401. /*
  402.  * The editor communicates with the display using a high level interface. A
  403.  * "TERM" structure holds useful variables, and indirect pointers to routines
  404.  * that do useful operations. The low level get and put routines are here too.
  405.  * This lets a terminal, in addition to having non standard commands, have
  406.  * funny get and put character code too. The calls might get changed to
  407.  * "termp->t_field" style in the future, to make it possible to run more than
  408.  * one terminal type.
  409.  */
  410. typedef struct  {
  411.     short    t_mrow;            /* max number of rows allowable */
  412.         short   t_nrow;                 /* current number of rows used  */
  413.         short   t_mcol;                 /* max Number of columns.       */
  414.         short   t_ncol;                 /* current Number of columns.   */
  415.     short    t_margin;        /* min margin for extended lines*/
  416.     short    t_scrsiz;        /* size of scroll region "    */
  417.     int    t_pause;        /* # times thru update to pause */
  418.         int     (*t_open)();            /* Open terminal at the start.  */
  419.         int     (*t_close)();           /* Close terminal at end.       */
  420.     int    (*t_kopen)();        /* Open keyboard        */
  421.     int    (*t_kclose)();        /* close keyboard        */
  422.         int     (*t_getchar)();         /* Get character from keyboard. */
  423.         int     (*t_putchar)();         /* Put character to display.    */
  424.         int     (*t_flush)();           /* Flush output buffers.        */
  425.         int     (*t_move)();            /* Move the cursor, origin 0.   */
  426.         int     (*t_eeol)();            /* Erase to end of line.        */
  427.         int     (*t_eeop)();            /* Erase to end of page.        */
  428.         int     (*t_beep)();            /* Beep.                        */
  429.     int    (*t_rev)();        /* set reverse video state    */
  430.     int    (*t_rez)();        /* change screen resolution    */
  431. #if    COLOR
  432.     int    (*t_setfor)();        /* set forground color        */
  433.     int    (*t_setback)();        /* set background color        */
  434. #endif
  435. }       TERM;
  436.  
  437. /*    TEMPORARY macros for terminal I/O  (to be placed in a machine
  438.                         dependant place later)    */
  439.  
  440. #define    TTopen        (*term.t_open)
  441. #define    TTclose        (*term.t_close)
  442. #define    TTkopen        (*term.t_kopen)
  443. #define    TTkclose    (*term.t_kclose)
  444. #define    TTgetc        (*term.t_getchar)
  445. #define    TTputc        (*term.t_putchar)
  446. #define    TTflush        (*term.t_flush)
  447. #define    TTmove        (*term.t_move)
  448. #define    TTeeol        (*term.t_eeol)
  449. #define    TTeeop        (*term.t_eeop)
  450. #define    TTbeep        (*term.t_beep)
  451. #define    TTrev        (*term.t_rev)
  452. #define    TTrez        (*term.t_rez)
  453. #if    COLOR
  454. #define    TTforg        (*term.t_setfor)
  455. #define    TTbacg        (*term.t_setback)
  456. #endif
  457.  
  458. /*    structure for the table of initial key bindings        */
  459.  
  460. typedef struct  {
  461.         short   k_code;                 /* Key code                     */
  462.         int     (*k_fp)();              /* Routine to handle it         */
  463. }       KEYTAB;
  464.  
  465. /*    structure for the name binding table        */
  466.  
  467. typedef struct {
  468.     char *n_name;        /* name of function key */
  469.     int (*n_func)();    /* function name is bound to */
  470. }    NBIND;
  471.  
  472. /*    The editor holds deleted text chunks in the KILL buffer. The
  473.     kill buffer is logically a stream of ascii characters, however
  474.     due to its unpredicatable size, it gets implemented as a linked
  475.     list of chunks. (The d_ prefix is for "deleted" text, as k_
  476.     was taken up by the keycode structure)            */
  477.  
  478. typedef    struct KILL {
  479.     struct KILL *d_next;    /* link to next chunk, NULL if last */
  480.     char d_chunk[KBLOCK];    /* deleted text */
  481. } KILL;
  482.  
  483.